﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BAL;
namespace QuanLyTiemNET_DEV_LINQ
{
    public partial class XtraFormThemPhieuThueMay : DevExpress.XtraEditors.XtraForm
    {
        public XtraFormThemPhieuThueMay()
        {
            InitializeComponent();
        }

        private void XtraFormThemPhieuThueMay_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = BAL_KHACHHANG.LayThongTinKH();
            comboBox1.DisplayMember = "HoTen";
            comboBox1.ValueMember = "MaKhach";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string err=null;
            try
            {
                float chietKhau=BAL_KHACHHANG.LayChietKhauKH(comboBox1.SelectedValue.ToString());
                if (BAL_PHIEUTHUEMAY.ThemPTM(ref err, comboBox1.SelectedValue.ToString(),0, chietKhau,0))
                {
                    DataTableReader dtr;
                    dtr = BAL_PHIEUTHUEMAY.LayThongTinPTM().CreateDataReader();
                    while(dtr.Read())
                    {
                        FrmPhongMay.maPhieuThueMay = int.Parse(dtr["MaPhieu"].ToString());
                    }

                    MessageBox.Show("Thành công!!!");
                    FrmPhongMay.themPhieuThanhCong = true;
                    
                    this.Close();
                }
                else
                    MessageBox.Show("Lỗi " + err);
            }
            catch(Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }
    }
}